package com.cn.xiaonuo.tcrfinance.tcragents.service.impl;

import cn.hutool.core.convert.Convert;
import com.cn.xiaonuo.common.entity.BusinessMessage;
import com.cn.xiaonuo.tcrfinance.tcragents.entiy.*;
import com.cn.xiaonuo.tcrfinance.tcragents.service.GzFinanceService;
import com.cn.xiaonuo.tcrfinance.tcragents.utils.GzAgentCst;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;
import java.util.Map;

/**
 * @author ＹｕＨａｏ·ｐｅｎｇ
 * @date 2022年01月25日 14:48
 */
@Service
public class GzFinanceServiceImpl implements GzFinanceService {

    @Autowired
    Environment env;

    @Autowired
    RestTemplate restTemplate;


    /**
     * 财务结算
     */
    @Override
    public BusinessMessage financialClosing(GzAgentRoyalty roy) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialClosing, roy, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }

    /**
     * 财务提成明细
     */
    @Override
    public BusinessMessage financialRoyDetails(GzAgentRoyalty roy) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialRoyDetails, roy, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }

    /**
     * 财务数据结账
     */
    @Override
    public BusinessMessage financialSureRoy(List<GzAgentRoyalty> royList) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialSureRoy, royList, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }

    /**
     * 财务提成
     */
    @Override
    public BusinessMessage financialTolRoy(GzAgentRoyalty roy) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialTolRoy, roy, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }

    /**
     * @param roy
     */
    @Override
    public BusinessMessage financialDetailsRoy(GzAgentRoyalty roy) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialDetailsRoy, roy, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }


    /**
     * 所有周期
     */
    @Override
    public BusinessMessage financialCycles(AppsCyc appsCyc) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialCycles, appsCyc, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        message.setPageSize(Convert.toInt(data.get("pageSize")));
        message.setPageNum(Convert.toInt(data.get("pageNum")));
        message.setDataTol(Convert.toInt(data.get("dataTol")));
        return message;
    }


    /**
     * 运营中心业绩
     */
    @Override
    public BusinessMessage financialOpCycTrade(SlShop appsCyc) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialOpCycTrade, appsCyc, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        message.setPageSize(Convert.toInt(data.get("pageSize")));
        message.setPageNum(Convert.toInt(data.get("pageNum")));
        message.setDataTol(Convert.toInt(data.get("dataTol")));
        return message;
    }

    /**
     * 根据商家分提成总额
     */
    @Override
    public BusinessMessage financialSpRoyTolGb(AppsCyc appsCyc) {
        BusinessMessage<Object> message = new BusinessMessage<>();
         Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialSpRoyTolGb, appsCyc, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        message.setPageSize(Convert.toInt(data.get("pageSize")));
        message.setPageNum(Convert.toInt(data.get("pageNum")));
        message.setDataTol(Convert.toInt(data.get("dataTol")));
        return message;
    }



    /**
     * 代理总信息
     */
    @Override
    public BusinessMessage financialAgentTotalInfo(CycleInfo cInfo) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
            GzAgentCst.financialAgentTotalInfo, cInfo, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        return message;
    }

    /**
     * 获取代理业绩信息
     *
     * @param cInfo
     */
    @Override
    public BusinessMessage financialHasRoyAgentInfo(RoyCycInfo cInfo) {
        BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialHasRoyAgentInfo, cInfo, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        message.setPageSize(Convert.toInt(data.get("pageSize")));
        message.setPageNum(Convert.toInt(data.get("pageNum")));
        message.setDataTol(Convert.toInt(data.get("dataTol")));
        return message;
    }

    /**
     * 财务提成明细详细信息
     *
     * @param cInfo
     */
    @Override
    public BusinessMessage financialCycRoyDetails(RoyDetailInfo cInfo) {
         BusinessMessage<Object> message = new BusinessMessage<>();
        Map data = restTemplate.postForObject(env.getProperty("https.gzAgent") +
                GzAgentCst.financialCycRoyDetails, cInfo, Map.class);
        message.setCode(Convert.toStr(data.get("code")));
        message.setSuccess(Convert.toBool(data.get("success")));
        message.setData(data.get("data"));
        message.setMessage(Convert.toStr(data.get("msg")));
        message.setPageSize(Convert.toInt(data.get("pageSize")));
        message.setPageNum(Convert.toInt(data.get("pageNum")));
        message.setDataTol(Convert.toInt(data.get("dataTol")));
        return message;
    }


}


